﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.EntityModel;
using System.Runtime.Serialization;
using System.Diagnostics.Contracts;

namespace YasharEl.Infrastructure.ResourcesManagement
{
    [Serializable]
    public abstract class TranslatedDomainModelException : DomainModelException
    {
        #region ReadOnly Fields

        protected readonly IResourceManager resourceManager;

        #endregion

        #region Properties

        public virtual string TranslatedMessage
        {
            get { return resourceManager.GetString(ExceptionMessageResourceKey); }
        }

        #endregion

        #region Subclasses extension points

        protected abstract string ExceptionMessageResourceKey { get; }

        #endregion

        #region Constructors

        public TranslatedDomainModelException(IResourceManager resourceManager, string message)
            : base(message)
        {
            Contract.Requires<ArgumentNullException>(resourceManager != null, "resourceManager could not be null.");

            this.resourceManager = resourceManager;
        }

        public TranslatedDomainModelException(IResourceManager resourceManager, string message, Exception innerException)
            : base(message, innerException)
        {
            Contract.Requires<ArgumentNullException>(resourceManager != null, "resourceManager could not be null.");

            this.resourceManager = resourceManager;
        }

        protected TranslatedDomainModelException(SerializationInfo info, StreamingContext context) :
            base(info, context)
        {
        }

        #endregion
    }
}
